<div class="tab-pane active" id="access">
	<h5><?php echo t('page', 'Group Access'); ?></h5>
	<?php $form = $this->beginWidget('CActiveForm', array(
		'id' => 'access-modify-form',
		'method' => 'post',
		'action' => url('user/modifyaccess'),
		'enableClientValidation' => true,
		'clientOptions' => array(
			'validateOnSubmit' => true,
		),
	)); ?>
		<input type="hidden" name="id_user_role" class="id_user_role_hidden" />
		
		<label class="checkbox">
			<strong class="text-error"><?php echo t('page', 'Groups Not Permitted To Access'); ?></strong>
			<?php echo CHtml::checkBox('checkall_group_per', false, array('class' => 'checkallbox', 'data-checkall-select' => 'Access_id_group_not_permitted')); ?>
		</label>
		<?php echo CHtml::dropDownList('Access[id_group_not_permitted][]', '', $existedGroups, array('class' => 'chzn-select checkallselect', 'data-checkall-box' => 'checkall_group_per', 'data-placeholder' => t('info', 'Deny Acces To Groups...'), 'multiple' => true, 'style' => 'width: 350px;" tabindex="4')); ?>
		<br />
		
		<label class="checkbox">
			<strong class="text-success"><?php echo t('page', 'Groups Permitted To Access'); ?></strong>
			<?php echo CHtml::checkBox('checkall_group_deny', false, array('class' => 'checkallbox', 'data-checkall-select' => 'Access_id_group_permitted')); ?>
		</label>
		<?php echo CHtml::dropDownList('Access[id_group_permitted][]', '', $existedGroups, array('class' => 'chzn-select checkallselect', 'data-checkall-box' => 'checkall_group_deny', 'data-placeholder' => t('info', 'Allow Acces To Groups...'), 'multiple' => true, 'style' => 'width: 350px;" tabindex="4')); ?><br />

		<h5>Individual WHM Account Access (Overrides Group Permissions)</h5>
		<label class="checkbox">
			<strong class="text-error"><?php echo t('page', 'WHM Accounts Not Permitted To Access'); ?></strong>
			<?php echo CHtml::checkBox('checkall_account_per', false, array('class' => 'checkallbox', 'data-checkall-select' => 'Access_id_account_not_permitted')); ?>
		</label>
		<?php echo CHtml::dropDownList('Access[id_account_not_permitted][]', '', $existedWhmAccounts, array('class' => 'chzn-select checkallselect', 'data-checkall-box' => 'checkall_account_per', 'data-placeholder' => t('info', 'Deny Acces To WHM Accounts...'), 'multiple' => true, 'style' => 'width: 350px;" tabindex="4')); ?><br />
		
		<label class="checkbox">
			<strong class="text-success"><?php echo t('page', 'WHM Accounts Permitted To Access'); ?></strong>
			<?php echo CHtml::checkBox('checkall_account_deny', false, array('class' => 'checkallbox', 'data-checkall-select' => 'Access_id_account_permitted')); ?>
		</label>
		<?php echo CHtml::dropDownList('Access[id_account_permitted][]', '', $existedWhmAccounts, array('class' => 'chzn-select checkallselect', 'data-checkall-box' => 'checkall_account_deny', 'data-placeholder' => t('info', 'Allow Acces To WHM Accounts...'), 'multiple' => true, 'style' => 'width: 350px;" tabindex="4')); ?><br /><br />
		
		<?php echo CHtml::tag('button', array('class' => 'btn btn-small btn-primary', 'type' => 'submit', 'id' => 'save-role-access'), t ('buttons', 'Update WHM Account Access')); ?>
		<script>
			$(document).ready(function(){
//				$(".chzn-select-deselect").chosen({allow_single_deselect:true});

//				$('#Access_id_group_not_permitted option[value="3"]').attr('selected', true)
//				$('#Access_id_group_not_permitted').attr('disabled', true);
				$(".chzn-select").chosen(); 
//				$(".chzn-select").trigger('liszt:updated');

				$('.checkallbox').click(function(){
					if($(this).is(':checked')){
						$('#'+$(this).attr('data-checkall-select')+' option').attr('selected', true);
					}else{
						$('#'+$(this).attr('data-checkall-select')+' option').removeAttr('selected');
					}
					$('#'+$(this).attr('data-checkall-select')).change().trigger('liszt:updated');
				});

				$('.checkallselect').change(function(){
					var checkallbox = $('#'+$(this).attr('data-checkall-box'));
					checkallbox.attr('checked', true);
					$.each($(this).children('option'), function(k, v){
						if(!$(v).is(':selected')){
							checkallbox.removeAttr('checked');
							return true;
						}
					});
				});

				$('#Access_id_group_not_permitted').change(function(){
					$.each($(this).children('option:selected'), function(k, v){
						$('#Access_id_group_permitted option[value="'+$(v).val()+'"]').removeAttr('selected');
					});
					$(".chzn-select").trigger('liszt:updated');
				});
				$('#Access_id_group_permitted').change(function(){
					$.each($(this).children('option:selected'), function(k, v){
						$('#Access_id_group_not_permitted option[value="'+$(v).val()+'"]').removeAttr('selected');
					});
					$(".chzn-select").trigger('liszt:updated');
				});
				$('#Access_id_account_not_permitted').change(function(){
					$.each($(this).children('option:selected'), function(k, v){
						$('#Access_id_account_permitted option[value="'+$(v).val()+'"]').removeAttr('selected');
					});
					$(".chzn-select").trigger('liszt:updated');
				});
				$('#Access_id_account_permitted').change(function(){
					$.each($(this).children('option:selected'), function(k, v){
						$('#Access_id_account_not_permitted option[value="'+$(v).val()+'"]').removeAttr('selected');
					});
					$(".chzn-select").trigger('liszt:updated');
				});

				$('#id_user_role').change(function(){
					var obj = $(this);
					$.ajax({
						type: 'get',
						url: <?php echo json_encode(url('user/getaccessdetail')); ?>,
						data: {'id_user_role': obj.val()},
						success: function(detail){
							$('#access-modify-form select option').removeAttr('selected');
							
							if(detail.role.supreme == 1){
//								$('#Access_id_account_permitted option').attr('selected', true);
								$('#Access_id_group_permitted option').attr('selected', true);
								
								$('#access-modify-form select').attr('disabled', 'disabled');
							}else{
								$('#access-modify-form select').removeAttr('disabled');
							}
							
							$.each(detail.userRolePermAccount, function(id_account, allow_or_deny){
								$('#Access_id_account_permitted option[value="'+id_account+'"]').attr('selected', true);
							});
							$.each(detail.userRoleDenyAccount, function(id_account, allow_or_deny){
								$('#Access_id_account_not_permitted option[value="'+id_account+'"]').attr('selected', true);
							});
							$.each(detail.userRolePermGroup, function(id_group, allow_or_deny){
								$('#Access_id_group_permitted option[value="'+id_group+'"]').attr('selected', true);
							});
							$.each(detail.userRoleDenyGroup, function(id_group, allow_or_deny){
								$('#Access_id_group_not_permitted option[value="'+id_group+'"]').attr('selected', true);
							});

							$(".chzn-select").trigger('liszt:updated');
						},
						dataType: 'json'
					});
				});

				$('#save-role-access').click(function(){
					$('#access-modify-form select').removeAttr('disabled');
				});
				
//				$('#save-role-access').click(function(){
//					$.ajax({
//						type: 'post',
//						url: <?php echo json_encode(url('user/midifypermission')); ?>,
//						data: $('#access-modify-form').serialize(),
//						success: function(ret){
//							
//						},
//						dataType: 'json'
//					});
//				});
			});
		</script>
	<?php $this->endWidget(); ?>
</div>